home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / java / io / StreamTokenizer.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  4.6 KB  |  502 lines

  1. package java.io;
  2.  
  3. import java.util.Arrays;
  4.  
  5. public class StreamTokenizer {
  6.    private Reader reader;
  7.    private InputStream input;
  8.    private char[] buf;
  9.    private int peekc;
  10.    private static final int NEED_CHAR = Integer.MAX_VALUE;
  11.    private static final int SKIP_LF = 2147483646;
  12.    private boolean pushedBack;
  13.    private boolean forceLower;
  14.    private int LINENO;
  15.    private boolean eolIsSignificantP;
  16.    private boolean slashSlashCommentsP;
  17.    private boolean slashStarCommentsP;
  18.    private byte[] ctype;
  19.    private static final byte CT_WHITESPACE = 1;
  20.    private static final byte CT_DIGIT = 2;
  21.    private static final byte CT_ALPHA = 4;
  22.    private static final byte CT_QUOTE = 8;
  23.    private static final byte CT_COMMENT = 16;
  24.    public int ttype;
  25.    public static final int TT_EOF = -1;
  26.    public static final int TT_EOL = 10;
  27.    public static final int TT_NUMBER = -2;
  28.    public static final int TT_WORD = -3;
  29.    private static final int TT_NOTHING = -4;
  30.    public String sval;
  31.    public double nval;
  32.  
  33.    private StreamTokenizer() {
  34.       this.reader = null;
  35.       this.input = null;
  36.       this.buf = new char[20];
  37.       this.peekc = Integer.MAX_VALUE;
  38.       this.LINENO = 1;
  39.       this.eolIsSignificantP = false;
  40.       this.slashSlashCommentsP = false;
  41.       this.slashStarCommentsP = false;
  42.       this.ctype = new byte[256];
  43.       this.ttype = -4;
  44.       this.wordChars(97, 122);
  45.       this.wordChars(65, 90);
  46.       this.wordChars(160, 255);
  47.       this.whitespaceChars(0, 32);
  48.       this.commentChar(47);
  49.       this.quoteChar(34);
  50.       this.quoteChar(39);
  51.       this.parseNumbers();
  52.    }
  53.  
  54.    /** @deprecated */
  55.    @Deprecated
  56.    public StreamTokenizer(InputStream var1) {
  57.       this();
  58.       if (var1 == null) {
  59.          throw new NullPointerException();
  60.       } else {
  61.          this.input = var1;
  62.       }
  63.    }
  64.  
  65.    public StreamTokenizer(Reader var1) {
  66.       this();
  67.       if (var1 == null) {
  68.          throw new NullPointerException();
  69.       } else {
  70.          this.reader = var1;
  71.       }
  72.    }
  73.  
  74.    public void resetSyntax() {
  75.       int var1 = this.ctype.length;
  76.  
  77.       while(true) {
  78.          --var1;
  79.          if (var1 < 0) {
  80.             return;
  81.          }
  82.  
  83.          this.ctype[var1] = 0;
  84.       }
  85.    }
  86.  
  87.    public void wordChars(int var1, int var2) {
  88.       if (var1 < 0) {
  89.          var1 = 0;
  90.       }
  91.  
  92.       if (var2 >= this.ctype.length) {
  93.          var2 = this.ctype.length - 1;
  94.       }
  95.  
  96.       while(var1 <= var2) {
  97.          byte[] var10000 = this.ctype;
  98.          int var10001 = var1++;
  99.          var10000[var10001] = (byte)(var10000[var10001] | 4);
  100.       }
  101.  
  102.    }
  103.  
  104.    public void whitespaceChars(int var1, int var2) {
  105.       if (var1 < 0) {
  106.          var1 = 0;
  107.       }
  108.  
  109.       if (var2 >= this.ctype.length) {
  110.          var2 = this.ctype.length - 1;
  111.       }
  112.  
  113.       while(var1 <= var2) {
  114.          this.ctype[var1++] = 1;
  115.       }
  116.  
  117.    }
  118.  
  119.    public void ordinaryChars(int var1, int var2) {
  120.       if (var1 < 0) {
  121.          var1 = 0;
  122.       }
  123.  
  124.       if (var2 >= this.ctype.length) {
  125.          var2 = this.ctype.length - 1;
  126.       }
  127.  
  128.       while(var1 <= var2) {
  129.          this.ctype[var1++] = 0;
  130.       }
  131.  
  132.    }
  133.  
  134.    public void ordinaryChar(int var1) {
  135.       if (var1 >= 0 && var1 < this.ctype.length) {
  136.          this.ctype[var1] = 0;
  137.       }
  138.  
  139.    }
  140.  
  141.    public void commentChar(int var1) {
  142.       if (var1 >= 0 && var1 < this.ctype.length) {
  143.          this.ctype[var1] = 16;
  144.       }
  145.  
  146.    }
  147.  
  148.    public void quoteChar(int var1) {
  149.       if (var1 >= 0 && var1 < this.ctype.length) {
  150.          this.ctype[var1] = 8;
  151.       }
  152.  
  153.    }
  154.  
  155.    public void parseNumbers() {
  156.       for(int var1 = 48; var1 <= 57; ++var1) {
  157.          byte[] var10000 = this.ctype;
  158.          var10000[var1] = (byte)(var10000[var1] | 2);
  159.       }
  160.  
  161.       byte[] var2 = this.ctype;
  162.       var2[46] = (byte)(var2[46] | 2);
  163.       var2 = this.ctype;
  164.       var2[45] = (byte)(var2[45] | 2);
  165.    }
  166.  
  167.    public void eolIsSignificant(boolean var1) {
  168.       this.eolIsSignificantP = var1;
  169.    }
  170.  
  171.    public void slashStarComments(boolean var1) {
  172.       this.slashStarCommentsP = var1;
  173.    }
  174.  
  175.    public void slashSlashComments(boolean var1) {
  176.       this.slashSlashCommentsP = var1;
  177.    }
  178.  
  179.    public void lowerCaseMode(boolean var1) {
  180.       this.forceLower = var1;
  181.    }
  182.  
  183.    private int read() throws IOException {
  184.       if (this.reader != null) {
  185.          return this.reader.read();
  186.       } else if (this.input != null) {
  187.          return this.input.read();
  188.       } else {
  189.          throw new IllegalStateException();
  190.       }
  191.    }
  192.  
  193.    public int nextToken() throws IOException {
  194.       if (this.pushedBack) {
  195.          this.pushedBack = false;
  196.          return this.ttype;
  197.       } else {
  198.          byte[] var1 = this.ctype;
  199.          this.sval = null;
  200.          int var2 = this.peekc;
  201.          if (var2 < 0) {
  202.             var2 = Integer.MAX_VALUE;
  203.          }
  204.  
  205.          if (var2 == 2147483646) {
  206.             var2 = this.read();
  207.             if (var2 < 0) {
  208.                return this.ttype = -1;
  209.             }
  210.  
  211.             if (var2 == 10) {
  212.                var2 = Integer.MAX_VALUE;
  213.             }
  214.          }
  215.  
  216.          if (var2 == Integer.MAX_VALUE) {
  217.             var2 = this.read();
  218.             if (var2 < 0) {
  219.                return this.ttype = -1;
  220.             }
  221.          }
  222.  
  223.          this.ttype = var2;
  224.          this.peekc = Integer.MAX_VALUE;
  225.  
  226.          byte var3;
  227.          for(var3 = var2 < 256 ? var1[var2] : 4; (var3 & 1) != 0; var3 = var2 < 256 ? var1[var2] : 4) {
  228.             if (var2 == 13) {
  229.                ++this.LINENO;
  230.                if (this.eolIsSignificantP) {
  231.                   this.peekc = 2147483646;
  232.                   return this.ttype = 10;
  233.                }
  234.  
  235.                var2 = this.read();
  236.                if (var2 == 10) {
  237.                   var2 = this.read();
  238.                }
  239.             } else {
  240.                if (var2 == 10) {
  241.                   ++this.LINENO;
  242.                   if (this.eolIsSignificantP) {
  243.                      return this.ttype = 10;
  244.                   }
  245.                }
  246.  
  247.                var2 = this.read();
  248.             }
  249.  
  250.             if (var2 < 0) {
  251.                return this.ttype = -1;
  252.             }
  253.          }
  254.  
  255.          if ((var3 & 2) != 0) {
  256.             boolean var20 = false;
  257.             if (var2 == 45) {
  258.                var2 = this.read();
  259.                if (var2 != 46 && (var2 < 48 || var2 > 57)) {
  260.                   this.peekc = var2;
  261.                   return this.ttype = 45;
  262.                }
  263.  
  264.                var20 = true;
  265.             }
  266.  
  267.             double var21 = (double)0.0F;
  268.             int var23 = 0;
  269.             byte var8 = 0;
  270.  
  271.             while(true) {
  272.                if (var2 == 46 && var8 == 0) {
  273.                   var8 = 1;
  274.                } else {
  275.                   if (48 > var2 || var2 > 57) {
  276.                      this.peekc = var2;
  277.                      if (var23 != 0) {
  278.                         double var9 = (double)10.0F;
  279.                         --var23;
  280.  
  281.                         while(var23 > 0) {
  282.                            var9 *= (double)10.0F;
  283.                            --var23;
  284.                         }
  285.  
  286.                         var21 /= var9;
  287.                      }
  288.  
  289.                      this.nval = var20 ? -var21 : var21;
  290.                      return this.ttype = -2;
  291.                   }
  292.  
  293.                   var21 = var21 * (double)10.0F + (double)(var2 - 48);
  294.                   var23 += var8;
  295.                }
  296.  
  297.                var2 = this.read();
  298.             }
  299.          } else if ((var3 & 4) != 0) {
  300.             int var19 = 0;
  301.  
  302.             do {
  303.                if (var19 >= this.buf.length) {
  304.                   this.buf = Arrays.copyOf(this.buf, this.buf.length * 2);
  305.                }
  306.  
  307.                this.buf[var19++] = (char)var2;
  308.                var2 = this.read();
  309.                var3 = var2 < 0 ? 1 : (var2 < 256 ? var1[var2] : 4);
  310.             } while((var3 & 6) != 0);
  311.  
  312.             this.peekc = var2;
  313.             this.sval = String.copyValueOf(this.buf, 0, var19);
  314.             if (this.forceLower) {
  315.                this.sval = this.sval.toLowerCase();
  316.             }
  317.  
  318.             return this.ttype = -3;
  319.          } else if ((var3 & 8) != 0) {
  320.             this.ttype = var2;
  321.             int var18 = 0;
  322.  
  323.             int var5;
  324.             for(var5 = this.read(); var5 >= 0 && var5 != this.ttype && var5 != 10 && var5 != 13; this.buf[var18++] = (char)var2) {
  325.                if (var5 == 92) {
  326.                   var2 = this.read();
  327.                   int var6 = var2;
  328.                   if (var2 >= 48 && var2 <= 55) {
  329.                      var2 -= 48;
  330.                      int var7 = this.read();
  331.                      if (48 <= var7 && var7 <= 55) {
  332.                         var2 = (var2 << 3) + (var7 - 48);
  333.                         var7 = this.read();
  334.                         if (48 <= var7 && var7 <= 55 && var6 <= 51) {
  335.                            var2 = (var2 << 3) + (var7 - 48);
  336.                            var5 = this.read();
  337.                         } else {
  338.                            var5 = var7;
  339.                         }
  340.                      } else {
  341.                         var5 = var7;
  342.                      }
  343.                   } else {
  344.                      switch (var2) {
  345.                         case 97:
  346.                            var2 = 7;
  347.                            break;
  348.                         case 98:
  349.                            var2 = 8;
  350.                         case 99:
  351.                         case 100:
  352.                         case 101:
  353.                         case 103:
  354.                         case 104:
  355.                         case 105:
  356.                         case 106:
  357.                         case 107:
  358.                         case 108:
  359.                         case 109:
  360.                         case 111:
  361.                         case 112:
  362.                         case 113:
  363.                         case 115:
  364.                         case 117:
  365.                         default:
  366.                            break;
  367.                         case 102:
  368.                            var2 = 12;
  369.                            break;
  370.                         case 110:
  371.                            var2 = 10;
  372.                            break;
  373.                         case 114:
  374.                            var2 = 13;
  375.                            break;
  376.                         case 116:
  377.                            var2 = 9;
  378.                            break;
  379.                         case 118:
  380.                            var2 = 11;
  381.                      }
  382.  
  383.                      var5 = this.read();
  384.                   }
  385.                } else {
  386.                   var2 = var5;
  387.                   var5 = this.read();
  388.                }
  389.  
  390.                if (var18 >= this.buf.length) {
  391.                   this.buf = Arrays.copyOf(this.buf, this.buf.length * 2);
  392.                }
  393.             }
  394.  
  395.             this.peekc = var5 == this.ttype ? Integer.MAX_VALUE : var5;
  396.             this.sval = String.copyValueOf(this.buf, 0, var18);
  397.             return this.ttype;
  398.          } else if (var2 != 47 || !this.slashSlashCommentsP && !this.slashStarCommentsP) {
  399.             if ((var3 & 16) == 0) {
  400.                return this.ttype = var2;
  401.             } else {
  402.                while((var2 = this.read()) != 10 && var2 != 13 && var2 >= 0) {
  403.                }
  404.  
  405.                this.peekc = var2;
  406.                return this.nextToken();
  407.             }
  408.          } else {
  409.             var2 = this.read();
  410.             if (var2 == 42 && this.slashStarCommentsP) {
  411.                for(int var4 = 0; (var2 = this.read()) != 47 || var4 != 42; var4 = var2) {
  412.                   if (var2 == 13) {
  413.                      ++this.LINENO;
  414.                      var2 = this.read();
  415.                      if (var2 == 10) {
  416.                         var2 = this.read();
  417.                      }
  418.                   } else if (var2 == 10) {
  419.                      ++this.LINENO;
  420.                      var2 = this.read();
  421.                   }
  422.  
  423.                   if (var2 < 0) {
  424.                      return this.ttype = -1;
  425.                   }
  426.                }
  427.  
  428.                return this.nextToken();
  429.             } else if (var2 == 47 && this.slashSlashCommentsP) {
  430.                while((var2 = this.read()) != 10 && var2 != 13 && var2 >= 0) {
  431.                }
  432.  
  433.                this.peekc = var2;
  434.                return this.nextToken();
  435.             } else if ((var1[47] & 16) == 0) {
  436.                this.peekc = var2;
  437.                return this.ttype = 47;
  438.             } else {
  439.                while((var2 = this.read()) != 10 && var2 != 13 && var2 >= 0) {
  440.                }
  441.  
  442.                this.peekc = var2;
  443.                return this.nextToken();
  444.             }
  445.          }
  446.       }
  447.    }
  448.  
  449.    public void pushBack() {
  450.       if (this.ttype != -4) {
  451.          this.pushedBack = true;
  452.       }
  453.  
  454.    }
  455.  
  456.    public int lineno() {
  457.       return this.LINENO;
  458.    }
  459.  
  460.    public String toString() {
  461.       String var1;
  462.       switch (this.ttype) {
  463.          case -4:
  464.             var1 = "NOTHING";
  465.             break;
  466.          case -3:
  467.             var1 = this.sval;
  468.             break;
  469.          case -2:
  470.             var1 = "n=" + this.nval;
  471.             break;
  472.          case -1:
  473.             var1 = "EOF";
  474.             break;
  475.          case 0:
  476.          case 1:
  477.          case 2:
  478.          case 3:
  479.          case 4:
  480.          case 5:
  481.          case 6:
  482.          case 7:
  483.          case 8:
  484.          case 9:
  485.          default:
  486.             if (this.ttype < 256 && (this.ctype[this.ttype] & 8) != 0) {
  487.                var1 = this.sval;
  488.             } else {
  489.                char[] var2 = new char[3];
  490.                var2[0] = var2[2] = '\'';
  491.                var2[1] = (char)this.ttype;
  492.                var1 = new String(var2);
  493.             }
  494.             break;
  495.          case 10:
  496.             var1 = "EOL";
  497.       }
  498.  
  499.       return "Token[" + var1 + "], line " + this.LINENO;
  500.    }
  501. }
  502.